package main.Q1301_1400;

import java.util.HashMap;
import java.util.Map;

public class Q1391_1400 {
    public static void main(String[] args) {
        System.out.println("Question1391：");
        System.out.println("Question1392：");
        System.out.println("Question1393：");
        System.out.println("Question1394：");
        System.out.println("Question1395：统计作战单位数");
        System.out.println("Question1396：");
        System.out.println("Question1397：");
        System.out.println("Question1398：");
        System.out.println("Question1399：");
        System.out.println("Question1400：构造 K 个回文字符串");
    }
}

class Question1395 {
    public int numTeams(int[] rating) {
        int len = rating.length;
        int[] up = new int[len], down = new int[len];
        int count = 0;
        for (int i = 0; i < len; i++) {
            for (int j = i - 1; j >= 0; j--) {
                if (rating[j] > rating[i]) {//比它大，找降序
                    count += down[j];
                    down[i]++;
                } else if (rating[j] < rating[i]) {
                    count += up[j];
                    up[i]++;
                }
            }
        }
        return count;
    }
}

class Question1400 {
    public boolean canConstruct(String s, int k) {
        int right = s.length();// 右边界为字符串的长度
        int[] count = new int[26];
        for (int i = 0; i < right; i++) {
            count[s.charAt(i) - 'a']++;
        }
        int left = 0;// 左边界为出现奇数次字符的个数
        for (int i = 0; i < 26; i++) {
            if (count[i] % 2 == 1) {
                left++;
            }
        }
        // 注意没有出现奇数次的字符的特殊情况
        left = Math.max(left, 1);
        return left <= k && k <= right;
    }
}